import json
import pymysql
import requests

if __name__ == '__main__':
    url="http://www.zjsfgkw.cn/Notice/NoticeKTSearch"
    headers = {
        "Host": "www.zjsfgkw.cn",
        "Origin": "http://www.zjsfgkw.cn",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",
    }
    for i in range(1000):
        fromdata = {
            "pageno": i,
            "pagesize": "10",
            "cbfy": "全部",
        }
        req = requests.post(url, data=fromdata,headers=headers)
        json_str = json.loads(req.text)
        # for i in json_str["list"]:
        #     database = pymysql.connect("localhost", "root", "Love1303", "work_1", charset='utf8')
        #     cursor = database.cursor()
        #     sql = "INSERT INTO data(法院,法庭,开庭日期,排期日期,案号,案由,承办部门,审判长,公诉人,被告人)\
        #                             VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"% \
        #           (i['FY'],i['CBFY'], i['KTRQSTRING'],i['PQRQ'],i['AH'],i['AY'],i['CBBM'],i['SPZ'],i['YG'],i['BG'])
        #     try:
        #         cursor.execute(sql)
        #         database.commit()
        #     except:
        #         database.rollback()
        print(json_str)
